package com.ruoyi.security.elevator.websocket;

import org.java_websocket.client.WebSocketClient;

import java.util.concurrent.ConcurrentHashMap;

public class WebSocketSessionManger {
    private static final ConcurrentHashMap<String, WebSocketClient> onlineWebsocket = new ConcurrentHashMap<>();



    public static boolean putSession(String address, WebSocketClient session){
        if(!onlineWebsocket.containsKey(address)){
            boolean success = onlineWebsocket.putIfAbsent(address, session)== null? true : false;
            return success;
        }
        return false;
    }


    public static WebSocketClient removeSession(String address){
        return onlineWebsocket.remove(address);
    }


    public static WebSocketClient getOnlineDevice(String address){
        if (onlineWebsocket.containsKey(address)){
            return onlineWebsocket.get(address);
        }
        return null;
    }
}
